<?php
namespace app\model;
use app\BaseModel;
use app\common\WechatPay;
use think\facade\Route;
use think\model\concern\SoftDelete;
use think\facade\Db;
use app\console\model\Admin;
class Company extends BaseModel
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
    protected $hidden = ['update_time','delete_time','sort','status'];




    protected static function onAfterWrite($data)
    {
//        if(!empty($data['account'])){
//            $ret = (new WechatPay())->addreceiver($data['receive_type'],$data['account']);
//
//            if ($ret["return_code"] == "SUCCESS" && $ret["result_code"] == "SUCCESS") {
//
//                win('分账接收方成功', Route::buildUrl('index'));
//            }
//            if ($ret["return_code"] == "SUCCESS" && $ret["result_code"] == "FAIL") {
//                fail($ret['err_code_des']);
//
//            }
//        }

      if(!empty($data['admin_name'])){
          $admin = Admin::where('admin_name', $data['admin_name'])->find();
          if (empty($admin)) {
              $admin_id = Db::name('admin')->insertGetId(['admin_name' => $data['admin_name'], 'admin_password' => 123456, 'data_id_str' => $data['id'], 'url' => 'console/shop/index']);
              Db::name('admin_role')->insertGetId(['admin_id' => $admin_id, 'role_id' => 5]);
          }
      }



    }






}